package com.example.controller;

import com.example.dto.RecordResult;
import com.example.dto.Result;
import com.example.entity.Record;
import com.example.service.RecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping(value = "/record")
@Api("对记录表的操作")
public class RecordController {

    @Autowired
    private RecordService recordService;

    @ResponseBody
    @RequestMapping(value = "/getMyRecord", method = RequestMethod.POST)
    @ApiOperation(value = "获取当前用户的记录", notes = "发送用户id给服务器，标识为：userId")
    public Result<RecordResult> getMyRecord(@RequestParam("userId") String userId){
        Result<RecordResult> result = new Result<>();
        RecordResult recordResult = new RecordResult();
        List<Record> list = recordService.getRecordsByUserIdSortByTime(userId);
        List<Record> list1 = recordService.getRecordsByUserIdSortByGrade(userId);
        recordResult.setSortByTime(list);
        recordResult.setSortByGrade(list1);
        return result.ok("当前用户的所有记录", recordResult);
    }

}
